<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fns" uri="http://java.sun.com/jsp/jstl/functionss" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Home - BioCode</title>

</head>
<body>
<div id="main">
    <div id="tool-header">
        <div class="row content-container" style="padding-bottom: 0">
            <div class="col-md-12">
                <h1 class="tool-title"><a href="${host}/tools/${tool.id}/show">${tool.name}</a>
                    <small>${tool.desc}</small>
                </h1>
            </div>
        </div>
        <ul class="nav nav-tabs" id="tool-nav-tab">
            <li><a href="${host}/tools/${tool.id}/show"><i class="fa fa-home"></i> Home</a></li>
            <li><a href="${host}/tools/${tool.id}/manual"><i class="fa fa-book"></i> Manual</a></li>
            <li class="active"><a href="${host}/tools/${tool.id}/releases"><i class="fa fa-download"></i> Downloads</a>
            </li>
            <li><a href="${host}/tools/${tool.id}/stat"><i class="fa fa-bar-chart"></i> Statistics</a></li>
        </ul>
    </div>
    <c:choose>
        <c:when test="${fn:length(releases) < 1}">
            <div class="content-container" style="padding-top: 0px">
                <div class="row">
                    <div class="col-md-10">
                        <div class="empty-placeholder"><p>No releases</p></div>
                    </div>
                    <c:if test="${currentUser.id == tool.user.id}">
                        <div class="col-md-2"><a class="btn btn-default btn-block"
                                                 href="${host}/tools/${tool.id}/releases/new"><i class="fa fa-plus"></i> New
                            Release</a></div>
                    </c:if>
                </div>
            </div>

        </c:when>
        <c:otherwise>
            <div class="content-container" style="padding-top: 0px">
                <div class="row">
                    <div class="col-md-3">
                        <h4>Releases</h4>
                        <div class="list-group">
                            <c:forEach items="${releases}" var="release">
                                <a class="list-group-item <c:if test="${release.version == version}">active</c:if>" href="${host}/tools/${tool.id}/releases/${release.version}">
                                <strong>${release.version}</strong><span class="badge"><fmt:formatDate value="${release.createdAt}"
                                                                                                       pattern="yyyy-MM-dd"/></span></a>
                            </c:forEach>
                        </div>


                        <c:if test="${currentUser.id == tool.user.id}">
                        
                        <div class="btn-group btn-group-sm" style="margin-top: 10px">
                            <a class="btn btn-default" href="${host}/tools/${tool.id}/releases/${release.version}/edit">
                                <i class="fa fa-edit"></i> Edit</a>
                            <a class="btn btn-default" href="${host}/tools/${tool.id}/releases/new"><i
                                class="fa fa-plus"></i> New Release</a>
                        </div>
                        </c:if>
                    </div>
                    <div class="col-md-9" style="border-left: 1px solid #eee">
                        <section class="text-justify">${release.note}</section>
                        <h3>Files
                            <small>Download Count: ${fns:calReleaseDownloadCount(release.id)}</small>
                        </h3>
                        <c:if test="${fn:length(fileNames)<1}">
                            <div class="empty-placeholder"><p>No files to be downloaded</p></div>
                        </c:if>
                        <c:if test="${fn:length(fileNames)>0}">
                        <ul>
                            <c:forEach items="${fileNames}" var="item">
                            <li><a href="${host}/tools/${tool.id}/releases/${release.version}/file/download?filename=${item}">${item}</a></li>
                            </c:forEach>
                        </ul>
                        </c:if>
                    </div>
                </div>
            </div>

        </c:otherwise>
    </c:choose>


</div>

</body>

</html>
